﻿@model UI.ServiceReference1.traineeModel

@{
    ViewBag.Title = "trainee";
    Layout = "~/Views/Shared/ShouYe.cshtml";
}
<script src="~/BootstrapSouce/js/jquery.min.js"></script>
<link href="~/BootstrapSouce/css/bootstrap.min.css" rel="stylesheet" />
<script src="~/BootstrapSouce/js/bootstrap.min.js"></script>

<h3>培训人员</h3>
<a href="#" class="btn" data-toggle="modal" data-target="#add" style="float:right">添加人员</a>
<table id="t" class="table table-bordered table-hover definewidth m10">
    <thead>
        <tr>
            <th>人员编号</th>
            <th>人员姓名</th>
            <th>主板单位</th>
            <th>培训方式</th>
            <th>负责人</th>
            <th>考核成绩</th>
            <th>培训教师</th>
            <th>课时</th>
            <th>培训科目</th>
            <th>培训类型</th>
            <th>操作</th>
        </tr>
    </thead>
    <tbody></tbody>
</table>
<div id="pagediv"></div>
<div class="modal fade" id="add" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height:500px;width:500px;left:100px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
                <h4 class="modal-title" id="myModalLabel">添加人员培训</h4>
            </div>
            <div class=" modal-body">
                <table class="table">
                    <tr>
                        <td>培训人员:</td>
                        <td><select id="user" class="form-control"></select></td>
                    </tr>
                    <tr>
                        <td>主板单位:</td>
                        <td><input type="text" id="train_sponsor" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>培训方式:</td>
                        <td>
                            <select id="train_way" class=" form-control">
                                <option value="讲授法">讲授法</option>
                                <option value="视听技术法">视听技术法</option>
                                <option value="讨论法">讨论法</option>
                                <option value="案例研讨法">案例研讨法</option>
                                <option value="角色扮演法">角色扮演法</option>
                                <option value="自学法">自学法</option>
                                <option value="互动小组法">互动小组法</option>
                                <option value="网络培训法">网络培训法</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>负责人姓名:</td>
                        <td><input type="text" id="principal" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>考核成绩:</td>
                        <td><input type="text" id="train_grade" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>培训教师:</td>
                        <td><input type="text" id="train_teacher" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>课时:</td>
                        <td><input type="text" id="train_hour" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>培训科目:</td>
                        <td>
                            <select id="train_subjects" class=" form-control">
                                <option value="第一部分  从校园到社会的跨越">第一部分  从校园到社会的跨越</option>
                                <option value="第二部分 初入职场四个意识的转变">第二部分 初入职场四个意识的转变</option>
                                <option value="第三部分 人在职场应该具备的心态 ">第三部分 人在职场应该具备的心态 </option>
                                <option value="第四部分 人在职场应该懂得的礼仪">第四部分 人在职场应该懂得的礼仪</option>
                                <option value="第五部分 综合能力培训">第五部分 综合能力培训</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>培训类型:</td>
                        <td><select id="traintype" class=" form-control"></select></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="funadd()" class="btn btn-primary">
                    发布
                </button>
            </div>
        </div>
    </div>
</div>
@* ------------------------------------------------------分割线 一下是修改的模态框----------------------------------------------------------------------- *@
<div class="modal fade" id="upt" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="height:500px;width:500px;left:100px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    <span class="glyphicon glyphicon-remove"></span>
                </button>
                <h4 class="modal-title" id="myModalLabel">修改人员培训</h4>
            </div>
            <div class=" modal-body">
                <table class="table">
                    <tr>
                        <td>培训人员:</td>
                        <td><select id="user1" class="form-control"></select></td>
                    </tr>
                    <tr>
                        <td>主板单位:</td>
                        <td><input type="text" id="train_sponsor1" class=" form-control" /> <input id="trainee_id" type="hidden" /></td>
                    </tr>
                    <tr>
                        <td>培训方式:</td>
                        <td>
                            <select id="train_way1" class=" form-control">
                                <option value="讲授法">讲授法</option>
                                <option value="视听技术法">视听技术法</option>
                                <option value="讨论法">讨论法</option>
                                <option value="案例研讨法">案例研讨法</option>
                                <option value="角色扮演法">角色扮演法</option>
                                <option value="自学法">自学法</option>
                                <option value="互动小组法">互动小组法</option>
                                <option value="网络培训法">网络培训法</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>负责人姓名:</td>
                        <td><input type="text" id="principal1" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>考核成绩:</td>
                        <td><input type="text" id="train_grade1" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>培训教师:</td>
                        <td><input type="text" id="train_teacher1" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>课时:</td>
                        <td><input type="text" id="train_hour1" class=" form-control" /></td>
                    </tr>
                    <tr>
                        <td>培训科目:</td>
                        <td>
                            <select id="train_subjects1" class=" form-control">
                                <option value="第一部分  从校园到社会的跨越">第一部分  从校园到社会的跨越</option>
                                <option value="第二部分 初入职场四个意识的转变">第二部分 初入职场四个意识的转变</option>
                                <option value="第三部分 人在职场应该具备的心态 ">第三部分 人在职场应该具备的心态 </option>
                                <option value="第四部分 人在职场应该懂得的礼仪">第四部分 人在职场应该懂得的礼仪</option>
                                <option value="第五部分 综合能力培训">第五部分 综合能力培训</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>培训类型:</td>
                        <td><select id="traintype1" class=" form-control"></select></td>
                    </tr>
                </table>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default"
                        data-dismiss="modal">
                    关闭
                </button>
                <button type="button" onclick="funupt()" class="btn btn-primary">
                    修改
                </button>
            </div>
        </div>
    </div>
</div>
<script>
    var pagesize = 3;
    show(1);
    usershow();
    traintypeshow();
    function funadd()
    {
        var userID = $("#user").val();
        var train_sponsor = $("#train_sponsor").val();
        var train_way = $("#train_way").val();
        var principal = $("#principal").val();
        var train_grade = $("#train_grade").val();
        var train_teacher = $("#train_teacher").val();
        var train_hour = $("#train_hour").val();
        var train_subjects = $("#train_subjects").val();
        var traintype_id = $("#traintype").val();
        $.ajax({
            url: "/Peixun/traineeADD",
            data: { userID: userID, train_sponsor: train_sponsor, train_way: train_way, principal: principal, train_grade: train_grade, train_teacher: train_teacher, train_hour: train_hour, train_subjects: train_subjects, traintype_id: traintype_id },
            type: "post",
            success:function(obj)
            {
                if(obj>0)
                {
                    alert('添加成功');
                    location.href = '/Peixun/trainee';
                }
                else
                {
                    alert('添加失败');   
                }
            }
        })
    }
    function usershow()
    {
        $.ajax({
            url: "/Peixun/usershow",
            type: "get",
            dateType: "json",
            success:function(obj)
            {
                obj = JSON.parse(obj);
                $("#user").empty();
                $("#user1").empty();
                for (var i = 0; i < obj.length; i++) {
                    $("#user").append("<option value='" + obj[i].Staff_ID + "'>" + obj[i].Staff_Name + "</option>");
                    $("#user1").append("<option value='" + obj[i].Staff_ID + "'>" + obj[i].Staff_Name + "</option>");
                }
            }
        })
    }
    function traintypeshow()
    {
        $.ajax({
            url: "/Peixun/traintypeshow",
            type: "get",
            dateType: "json",
            success: function (obj) {
                obj = JSON.parse(obj);
                $("#traintype").empty();
                $("#traintype1").empty();
                for (var i = 0; i < obj.length; i++) {
                    $("#traintype").append("<option value='" + obj[i].traintype_id + "'>" + obj[i].traintype_name + "</option>");
                    $("#traintype1").append("<option value='" + obj[i].traintype_id + "'>" + obj[i].traintype_name + "</option>");
                }
            }
        })
    }
    function show(pageindex)
    {
        $.ajax({
            url: "/Peixun/traineeshow",
            type: "get",
            data:{pageindex:pageindex,pagesize:pagesize},
            success:function(obj)
            {
                obj = JSON.parse(obj);
               // obj = eval(""+obj+"");
                
                $("#t tbody").empty();
                var str = "";
                for (var i = 0; i < obj.trainee.length; i++) {
                    str += "<tr><td>" + obj.trainee[i].trainee_id + "</td>";
                    str += "<td>" + obj.trainee[i].userName + "</td>";
                    str += "<td>" + obj.trainee[i].train_sponsor + "</td>";
                    str += "<td>" + obj.trainee[i].train_way + "</td>";
                    str += "<td>" + obj.trainee[i].principal + "</td>";
                    str += "<td>" + obj.trainee[i].train_grade + "</td>";
                    str += "<td>" + obj.trainee[i].train_teacher + "</td>";
                    str += "<td>" + obj.trainee[i].train_hour + "</td>";
                    str += "<td>" + obj.trainee[i].train_subjects + "</td>";
                    str += "<td>" + obj.trainee[i].traintype_name + "</td>";
                    str += "<td><a href='/Peixun/traineedel?trainee_id=" + obj.trainee[i].trainee_id + "'>删除</a><input type='button' value='修改'onclick='upt(" + obj.trainee[i].trainee_id + ")'data-toggle='modal' data-target='#upt'class='btn btn-primarys' /></td></tr>";
                }
                $("#t tbody").append(str);
                showpage(obj.count);
            }
        })
    }
    function showpage(count)
    {
        $("#pagediv").empty();
        var i = Math.ceil(count / pagesize);
        //显示页码
        for (var k = 1; k <= i; k++) {
            $("#pagediv").append("<a href='#' onclick=show(" + k + ")  class='btn btn-primarys'>" + k + "</a>")
        }
    }
    function upt(trainee_id)
    {
        $.ajax({
            url: "/Peixun/traineeft?trainee_id=" + trainee_id,
            type: "get",
            dateType: "json",
            success:function(obj)
            {
                obj = JSON.parse(obj);
                for (var i = 0; i < obj.length; i++) {
                    $("#user1").val(obj[i].userID);
                    $("#train_sponsor1").val(obj[i].train_sponsor);
                    $("#train_way1").val(obj[i].train_way);
                    $("#principal1").val(obj[i].principal);
                    $("#train_grade1").val(obj[i].train_grade);
                    $("#train_teacher1").val(obj[i].train_teacher);
                    $("#train_hour1").val(obj[i].train_hour);
                    $("#train_subjects1").val(obj[i].train_subjects);
                    $("#traintype1").val(obj[i].traintype_id);
                    $("#trainee_id").val(obj[i].trainee_id);
                }            
            }
        })   
    }
    function funupt()
    {
        var trainee_id = $("#trainee_id").val();
        var userID = $("#user1").val();
        var train_sponsor = $("#train_sponsor1").val();
        var train_way = $("#train_way1").val();
        var principal = $("#principal1").val();
        var train_grade = $("#train_grade1").val();
        var train_teacher = $("#train_teacher1").val();
        var train_hour = $("#train_hour1").val();
        var train_subjects = $("#train_subjects1").val();
        var traintype_id = $("#traintype1").val();
        $.ajax({
            url: "/Peixun/traineeUPT",
            data: {trainee_id:trainee_id,userID: userID, train_sponsor: train_sponsor, train_way: train_way, principal: principal, train_grade: train_grade, train_teacher: train_teacher, train_hour: train_hour, train_subjects: train_subjects, traintype_id: traintype_id },
            type: "post",
            success: function (obj) {
                if (obj > 0) {
                    alert('修改成功');
                    location.href = '/Peixun/trainee';
                }
                else {
                    alert('修改失败');
                }
            }
        })
    }
</script>    
             
             
             
             
             